package com.CST.controller.cb;

import com.CST.annotation.ResultObjectAnnotation;
import com.CST.common.api.Response;
import com.CST.common.api.ResultObject;
import com.CST.common.constant.DmlTypeConstant;
import com.CST.entity.cb.BdSysMenu;
import com.CST.service.cb.IBdSysMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 菜单管理
 * </p>
 *
 * @author: y
 * @create: 2021-09-27 14:51
 **/
@Api(tags = {"菜单管理"})
@RestController
@RequestMapping("/bdSysMenu")
@Log4j2
public class BdSysMenuController {

    @Autowired
    private IBdSysMenuService bdSysMenuService;

    @ApiOperation(value = "获取单个菜单", notes = "获取单个菜单")
    @GetMapping("/getSysMenu")
    public ResultObject getSyeMenus(@RequestParam("id") String id) {
        return ResultObject.successReturn(bdSysMenuService.getSyeMenu(id));
    }

    /**
     * <p>新建菜单</p >
     *
     * @param bdSysMenu
     * @return com.CST.common.api.Response
     *
     * @author y
     * @since 2021/09/27 15:50
     */
    @ApiOperation("新建菜单")
    @PostMapping("/insertSysMenu")
    public Response insertSysMenu(@RequestBody BdSysMenu bdSysMenu) {
        return Response.success(bdSysMenuService.insertSysMenu(bdSysMenu));
    }

    /**
     * <p>更新菜单表</p >
     *
     * @param bdSysMenu
     * @return int
     *
     * @author y
     * @since 2021/09/27 17:05
     */
    @ApiOperation("修改菜单")
    @PostMapping("/updateSysMenu")
    public ResultObject updateSysMenu(@RequestBody BdSysMenu bdSysMenu) {
        if (bdSysMenuService.updateSysMenu(bdSysMenu)) {
            return ResultObject.success(null, "修改成功");
        } else {
            return ResultObject.failed("修改菜单失败");
        }
    }

    @ApiOperation(value = "获取角色下菜单所有", notes = "获取角色下菜单所有")
    @GetMapping("/getSysMenuListByRole")
    public ResultObject getSysMenuListByRole(@RequestParam("roleId") String roleId) {
        return ResultObject.successReturn(bdSysMenuService.getSysMenuListByRole(roleId));
    }

    @ApiOperation(value = "获取全部菜单", notes = "获取全部菜单")
    @GetMapping("/getSysMenuAll")
    public ResultObject getSysMenu() {
        return ResultObject.successReturn(bdSysMenuService.getSysMenu());
    }

    @ApiOperation(value = "获取全部菜单1", notes = "获取全部菜单1")
    @GetMapping("/getMenuAll")
    public ResultObject getMenuAllTree(String name) {
        return ResultObject.successReturn(bdSysMenuService.getSysMenuLike(name));
    }

    @ApiOperation(value = "获取全部菜单2", notes = "获取全部菜单1")
    @GetMapping("/getMenuInfo")
    public ResultObject getMenuAll(String id) {
        return ResultObject.successReturn(bdSysMenuService.getMenuInfo(id));
    }


    @GetMapping("/getById/{id}")
    @ApiOperation("查看")
    @ResultObjectAnnotation(DmlTypeConstant.SELECT)
    public Object getById(@PathVariable String id) {
        return bdSysMenuService.getById(id);
    }


    @DeleteMapping("/delete")
    @ApiOperation("删除")
    @ResultObjectAnnotation(DmlTypeConstant.DELETE)
    public Object delete(@RequestParam String ids) {
        return bdSysMenuService.removeById(ids);
    }


}
